<?php


namespace app\api\model;


class SubjectAnalogRank extends BaseModel
{
    protected  $autoWriteTimestamp = true;

    /**
     * 添加排名
     * @param $data
     * @return array|false
     * @throws \Exception
     */
    public  function insertRank($data){
        return self::saveAll($data);
    }

    /**
     * 获取用户排名
     * @param $uid
     * @param $course
     * @param $car_status
     * @return array|false|\PDOStatement|string|\think\Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getUserRank($uid,$course,$car_status){
        return self::where('user_id','=',$uid)
                ->where('course','=',$course)
                ->where('car_status','=',$car_status)
                ->find();
    }

    /**
     * 获取排行榜
     * @param $t_id
     * @param $course
     * @param $car_status
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getRank($t_id,$course,$car_status){
        return self::where('t_id','=',$t_id)
            ->where('course','=',$course)
            ->where('car_status','=',$car_status)
            ->select();
    }

    /**
     * 获取最低分数
     * @param $t_id
     * @param $course
     * @param $car_status
     * @return mixed
     */
    public function getMinSore($t_id,$course,$car_status){
       return self::where('t_id','=',$t_id)
            ->where('course','=',$course)
            ->where('car_status','=',$car_status)
            ->min('sore');
    }

    /**
     * 获取最大时间
     * @param $t_id
     * @param $course
     * @param $car_status
     */
    public function getMaxTime($t_id,$course,$car_status){
        self::where('t_id','=',$t_id)
            ->where('course','=',$course)
            ->where('car_status','=',$car_status)
            ->max('time');
    }





}